using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LevelProgress : MonoBehaviour
{
    private MBattleController mBattleController;
    MBattleController MBattleController
    {
        get
        {
            if(mBattleController == null)
            {
                var mainUI = GetComponentInParent<MBattleMainUI>();
                if (mainUI)
                {
                    mBattleController = mainUI.MBattleController;
                }
                
                Init(mBattleController);
            }

            return mBattleController;
        }
    }

    private float levelEndPosz;

    [SerializeField] private Slider levelProgress;
    public Text curLevelText;
    public Text nextLevelText;
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    void Init(MBattleController mBattleController)
    {
        this.curLevelText.text = mBattleController.level.ToString();
        this.nextLevelText.text = (mBattleController.level + 1).ToString();
        
        //levelEndPosz = this.MBattleController.winChecker.transform.position.z;
        //levelEndPosz -= 4;
    }
    

    // Update is called once per frame
    void Update()
    {
        if (!this.MBattleController)
            return;
        
        if(MBattleController.GameStarted)
        {
            if (levelEndPosz <= 0) return;
            
           /* float curZ = MBattleController.me.transform.position.z;
            
            float rate = curZ / levelEndPosz;

            this.levelProgress.value = rate;*/
        }
    }
}
